.class public Lcom/melesta/engine/Cipher;
.super Ljava/lang/Object;
.source "Cipher.java"


# static fields
.field private static final cipher:Ljavax/crypto/Cipher;

.field private static final key128:Ljavax/crypto/spec/SecretKeySpec;

.field private static final key128Bytes:[B

.field private static final key192:Ljavax/crypto/spec/SecretKeySpec;

.field private static final key192Bytes:[B


# direct methods
.method static constructor <clinit>()V
    .locals 3

    .prologue
    .line 15
    const/16 v0, 0x18

    new-array v0, v0, [B

    fill-array-data v0, :array_0

    sput-object v0, Lcom/melesta/engine/Cipher;->key192Bytes:[B

    .line 17
    const/16 v0, 0x10

    new-array v0, v0, [B

    fill-array-data v0, :array_1

    sput-object v0, Lcom/melesta/engine/Cipher;->key128Bytes:[B

    .line 19
    new-instance v0, Ljavax/crypto/spec/SecretKeySpec;

    sget-object v1, Lcom/melesta/engine/Cipher;->key192Bytes:[B

    const-string v2, "AES"

    invoke-direct {v0, v1, v2}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V

    sput-object v0, Lcom/melesta/engine/Cipher;->key192:Ljavax/crypto/spec/SecretKeySpec;

    .line 20
    new-instance v0, Ljavax/crypto/spec/SecretKeySpec;

    sget-object v1, Lcom/melesta/engine/Cipher;->key128Bytes:[B

    const-string v2, "AES"

    invoke-direct {v0, v1, v2}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V

    sput-object v0, Lcom/melesta/engine/Cipher;->key128:Ljavax/crypto/spec/SecretKeySpec;

    .line 22
    invoke-static {}, Lcom/melesta/engine/Cipher;->createCipher()Ljavax/crypto/Cipher;

    move-result-object v0

    sput-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    return-void

    .line 15
    nop

    :array_0
    .array-data 0x1
        0x30t
        0x31t
        0x32t
        0x33t
        0x4t
        0x5t
        0x6t
        0x7t
        0x28t
        0x9t
        0x1at
        0xbt
        0xct
        0x1dt
        0xet
        0xft
        0x10t
        0x31t
        0x12t
        0x13t
        0x14t
        0x55t
        0x16t
        0x17t
    .end array-data

    .line 17
    :array_1
    .array-data 0x1
        0x31t
        0x31t
        0x12t
        0x13t
        0x24t
        0x45t
        0x6t
        0x7t
        0x28t
        0x1ft
        0x1at
        0xbt
        0xct
        0x1dt
        0x2et
        0x1ft
    .end array-data
.end method

.method public constructor <init>()V
    .locals 0

    .prologue
    .line 13
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method private static createCipher()Ljavax/crypto/Cipher;
    .locals 3

    .prologue
    .line 26
    :try_start_0
    const-string v1, "AES/ECB/PKCS7Padding"

    const-string v2, "BC"

    invoke-static {v1, v2}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;Ljava/lang/String;)Ljavax/crypto/Cipher;
    :try_end_0
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/security/NoSuchProviderException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljavax/crypto/NoSuchPaddingException; {:try_start_0 .. :try_end_0} :catch_2

    move-result-object v1

    .line 35
    .local v0, e:Ljava/security/NoSuchAlgorithmException;
    :goto_0
    return-object v1

    .line 27
    .end local v0           #e:Ljava/security/NoSuchAlgorithmException;
    :catch_0
    move-exception v0

    .line 28
    .restart local v0       #e:Ljava/security/NoSuchAlgorithmException;
    invoke-static {v0}, Lcom/melesta/engine/Error;->processException(Ljava/lang/Exception;)V

    .line 35
    :goto_1
    const/4 v1, 0x0

    goto :goto_0

    .line 29
    .end local v0           #e:Ljava/security/NoSuchAlgorithmException;
    :catch_1
    move-exception v0

    .line 30
    .local v0, e:Ljava/security/NoSuchProviderException;
    invoke-static {v0}, Lcom/melesta/engine/Error;->processException(Ljava/lang/Exception;)V

    goto :goto_1

    .line 31
    .end local v0           #e:Ljava/security/NoSuchProviderException;
    :catch_2
    move-exception v0

    .line 32
    .local v0, e:Ljavax/crypto/NoSuchPaddingException;
    invoke-static {v0}, Lcom/melesta/engine/Error;->processException(Ljava/lang/Exception;)V

    goto :goto_1
.end method

.method public static decrypt([B)[B
    .locals 1
    .parameter "input"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/security/InvalidKeyException;,
            Ljavax/crypto/ShortBufferException;,
            Ljavax/crypto/IllegalBlockSizeException;,
            Ljavax/crypto/BadPaddingException;
        }
    .end annotation

    .prologue
    .line 60
    sget-object v0, Lcom/melesta/engine/Cipher;->key192:Ljavax/crypto/spec/SecretKeySpec;

    invoke-static {p0, v0}, Lcom/melesta/engine/Cipher;->decrypt([BLjavax/crypto/spec/SecretKeySpec;)[B

    move-result-object v0

    return-object v0
.end method

.method public static decrypt([BLjavax/crypto/spec/SecretKeySpec;)[B
    .locals 7
    .parameter "input"
    .parameter "key"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/security/InvalidKeyException;,
            Ljavax/crypto/ShortBufferException;,
            Ljavax/crypto/IllegalBlockSizeException;,
            Ljavax/crypto/BadPaddingException;
        }
    .end annotation

    .prologue
    const/4 v2, 0x0

    .line 69
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    const/4 v1, 0x2

    invoke-virtual {v0, v1, p1}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V

    .line 70
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    array-length v1, p0

    invoke-virtual {v0, v1}, Ljavax/crypto/Cipher;->getOutputSize(I)I

    move-result v0

    new-array v4, v0, [B

    .line 71
    .local v4, out:[B
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    array-length v3, p0

    move-object v1, p0

    move v5, v2

    invoke-virtual/range {v0 .. v5}, Ljavax/crypto/Cipher;->update([BII[BI)I

    move-result v6

    .line 72
    .local v6, ptLength:I
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    invoke-virtual {v0, v4, v6}, Ljavax/crypto/Cipher;->doFinal([BI)I

    move-result v0

    add-int/2addr v6, v0

    .line 73
    return-object v4
.end method

.method public static decryptWeak([B)[B
    .locals 1
    .parameter "input"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/security/InvalidKeyException;,
            Ljavax/crypto/ShortBufferException;,
            Ljavax/crypto/IllegalBlockSizeException;,
            Ljavax/crypto/BadPaddingException;
        }
    .end annotation

    .prologue
    .line 64
    sget-object v0, Lcom/melesta/engine/Cipher;->key128:Ljavax/crypto/spec/SecretKeySpec;

    invoke-static {p0, v0}, Lcom/melesta/engine/Cipher;->decrypt([BLjavax/crypto/spec/SecretKeySpec;)[B

    move-result-object v0

    return-object v0
.end method

.method public static encrypt([B)[B
    .locals 1
    .parameter "input"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/security/NoSuchAlgorithmException;,
            Ljava/security/NoSuchProviderException;,
            Ljavax/crypto/NoSuchPaddingException;,
            Ljava/security/InvalidKeyException;,
            Ljavax/crypto/ShortBufferException;,
            Ljavax/crypto/IllegalBlockSizeException;,
            Ljavax/crypto/BadPaddingException;
        }
    .end annotation

    .prologue
    .line 40
    sget-object v0, Lcom/melesta/engine/Cipher;->key192:Ljavax/crypto/spec/SecretKeySpec;

    invoke-static {p0, v0}, Lcom/melesta/engine/Cipher;->encrypt([BLjavax/crypto/spec/SecretKeySpec;)[B

    move-result-object v0

    return-object v0
.end method

.method public static encrypt([BLjavax/crypto/spec/SecretKeySpec;)[B
    .locals 7
    .parameter "input"
    .parameter "key"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/security/NoSuchAlgorithmException;,
            Ljava/security/NoSuchProviderException;,
            Ljavax/crypto/NoSuchPaddingException;,
            Ljava/security/InvalidKeyException;,
            Ljavax/crypto/ShortBufferException;,
            Ljavax/crypto/IllegalBlockSizeException;,
            Ljavax/crypto/BadPaddingException;
        }
    .end annotation

    .prologue
    const/4 v2, 0x0

    .line 51
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    const/4 v1, 0x1

    invoke-virtual {v0, v1, p1}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V

    .line 53
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    array-length v1, p0

    invoke-virtual {v0, v1}, Ljavax/crypto/Cipher;->getOutputSize(I)I

    move-result v0

    new-array v4, v0, [B

    .line 54
    .local v4, cipherText:[B
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    array-length v3, p0

    move-object v1, p0

    move v5, v2

    invoke-virtual/range {v0 .. v5}, Ljavax/crypto/Cipher;->update([BII[BI)I

    move-result v6

    .line 55
    .local v6, ctLength:I
    sget-object v0, Lcom/melesta/engine/Cipher;->cipher:Ljavax/crypto/Cipher;

    invoke-virtual {v0, v4, v6}, Ljavax/crypto/Cipher;->doFinal([BI)I

    move-result v0

    add-int/2addr v6, v0

    .line 56
    return-object v4
.end method

.method public static encryptWeak([B)[B
    .locals 1
    .parameter "input"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/security/NoSuchAlgorithmException;,
            Ljava/security/NoSuchProviderException;,
            Ljavax/crypto/NoSuchPaddingException;,
            Ljava/security/InvalidKeyException;,
            Ljavax/crypto/ShortBufferException;,
            Ljavax/crypto/IllegalBlockSizeException;,
            Ljavax/crypto/BadPaddingException;
        }
    .end annotation

    .prologue
    .line 45
    sget-object v0, Lcom/melesta/engine/Cipher;->key128:Ljavax/crypto/spec/SecretKeySpec;

    invoke-static {p0, v0}, Lcom/melesta/engine/Cipher;->encrypt([BLjavax/crypto/spec/SecretKeySpec;)[B

    move-result-object v0

    return-object v0
.end method
